package org.lwj.logger.json.support;

import java.io.IOException;
import java.io.StringWriter;

import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;
import org.lwj.logger.json.JsonSerializer;
import org.lwj.logger.util.Util;

public class Jackson1xSerializer implements JsonSerializer {

	public String toJson(Object obj) {
		String json = "";
		if (obj != null) {
			try {
				StringWriter sw = new StringWriter();
				JsonGenerator gen = new JsonFactory().createJsonGenerator(sw);
				ObjectMapper mapper = new ObjectMapper();
				mapper.getSerializationConfig().setDateFormat(Util.longFormat);
				mapper.writeValue(gen, obj);
				json = sw.toString();
				sw.close();
			} catch (IOException e) {
			}
		}
		return json;
	}

}
